﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YJKSparseDistance.Properties;
using YJKGeometryFuncs.CurveUtility;

namespace YJKSparseDistance.ModelLayer
{
	internal class ObstructureCurveBean : BaseCurveBean
	{
		public ObstructureCurveBean(ObstructurePacker_EvacuationDistance inputPacker, double useZ)
		{
			this.m_thisPacker = inputPacker;
			this.m_lstCurvePacker = new List<BulidingCurvePakcer>();
			List<Curve> boundingBoxCurveAtZ = inputPacker.GetBoundingBoxCurveAtZ(useZ);
			if (boundingBoxCurveAtZ != null && boundingBoxCurveAtZ.Count != 0 && !(this.m_thisPacker.ThisElement is Stairs))
			{
				if (this.m_thisPacker.ThisElement is Railing)
				{
					this.RailingMethod(boundingBoxCurveAtZ);
					return;
				}
				this.DefultMethod(boundingBoxCurveAtZ);
			}
		}

		public override List<XYZ> LstAllFreeEnd
		{
			get
			{
				return base.GetFreeCurveFreeEnd(this.LstCurvePacker);
			}
		}

		private void StairsMethod(List<Curve> lstBoundingCurve)
		{
			foreach (Curve curve in lstBoundingCurve)
			{
				Curve curve2 = Utility.ExtendCurve(curve, double.Parse(Resources.Str_OffestValue));
				Curve inputCurve = CurveUtility.CreateOffsetCurve(curve2, double.Parse(Resources.Str_OffestValue));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(curve, this.m_thisPacker, false, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(curve2, this.m_thisPacker, true, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(inputCurve, this.m_thisPacker, true, true, false, false));
			}
		}

		private void RailingMethod(List<Curve> lstBoundingCurve)
		{
			for (int i = 0; i < lstBoundingCurve.Count; i += 5)
			{
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(lstBoundingCurve[i], this.m_thisPacker, false, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(lstBoundingCurve[i + 1], this.m_thisPacker, true, true, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(lstBoundingCurve[i + 2], this.m_thisPacker, true, true, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(lstBoundingCurve[i + 3], this.m_thisPacker, true, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(lstBoundingCurve[i + 4], this.m_thisPacker, true, false, false, false));
			}
		}

		private void DefultMethod(List<Curve> lstBoundingCurve)
		{
			foreach (Curve curve in lstBoundingCurve)
			{
				Curve curve2 = CurveUtility.CreateOffsetCurve(curve, -double.Parse(Resources.Str_OffestValue));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(curve, this.m_thisPacker, false, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(curve2, this.m_thisPacker, true, true, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(Line.CreateBound(curve2.GetEndPoint(0), curve.GetEndPoint(0)), this.m_thisPacker, true, false, false, false));
				this.m_lstCurvePacker.Add(new BulidingCurvePakcer(Line.CreateBound(curve2.GetEndPoint(1), curve.GetEndPoint(1)), this.m_thisPacker, true, false, false, false));
			}
		}

		private ObstructurePacker_EvacuationDistance m_thisPacker;
	}
}
